package com.mspbots.script.config;

import com.fasterxml.jackson.databind.JsonNode;
import com.mspbots.api.client.AttendanceClient;
import com.mspbots.api.client.TeamsClient;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableAsync;

import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;

@Slf4j
@Configuration
@EnableAsync
public class ScriptConfiguration {


    @Autowired
    private AttendanceClient attendanceClient;
    @Autowired
    private TeamsClient teamsClient;


    @Bean
    public ScriptEngine scriptEngineManager() {
        ScriptEngineManager factory = new ScriptEngineManager();
        return factory.getEngineByName("groovy");
    }

    @Bean
    public CommandLineRunner start() {
        return t -> {
            JsonNode result = attendanceClient.get("/tenantattendances/healthcheck").block();
            log.info("tenantattendances/healthcheck result: {}", result);

            JsonNode teamsResult = teamsClient.get("/message/healthcheck").block();
            log.info("tenantattendances/healthcheck result: {}", teamsResult);
        };

    }


}

